local vision = {
    spring = {
        --day = "images/colour_cubes/spring_day_cc.tex",
        dust = "images/colour_cubes/spring_day_cc.tex",
        night = "images/colour_cubes/spring_day_cc.tex",
    },
    summer = {
        --day = "images/colour_cubes/summer_day_cc.tex",
        dust = "images/colour_cubes/summer_day_cc.tex",
        night = "images/colour_cubes/summer_day_cc.tex",
    },
    autumn = {
        --day = "images/colour_cubes/day05_cc.tex",
        dust = "images/colour_cubes/day05_cc.tex",
        night = "images/colour_cubes/day05_cc.tex",
    },
    winter = {
        --day = "images/colour_cubes/snow_cc.tex",
        dust = "images/colour_cubes/snow_cc.tex",
        night = "images/colour_cubes/snow_cc.tex",
    },

}

local function OnForcedNightVisionDirty(inst)
    if inst.components.playervision ~= nil then
        if inst._forced_nightvision:value() and not inst.replica.inventory:EquipHasTag("nightvision") then
            inst.components.playervision:PushForcedNightVision(inst, 1, vision[TheWorld.state.season], true)
        else
            inst.components.playervision:PopForcedNightVision(inst)
        end
    end
end

local function OnPlayerDeactivated(inst)
    inst:RemoveEventCallback("onremove", OnPlayerDeactivated)
    if not TheNet:IsDedicated() then
        inst:RemoveEventCallback("onforcednightvisiondirty", OnForcedNightVisionDirty)
        inst:RemoveEventCallback("equip", OnForcedNightVisionDirty)
        inst:RemoveEventCallback("unequip", OnForcedNightVisionDirty)
    end
end

local function OnPlayerActivated(inst)
    inst:ListenForEvent("onremove", OnPlayerDeactivated)
    if not TheNet:IsDedicated() then
        inst:ListenForEvent("onforcednightvisiondirty", OnForcedNightVisionDirty)
        inst:ListenForEvent("equip", OnForcedNightVisionDirty)
        inst:ListenForEvent("unequip", OnForcedNightVisionDirty)
        OnForcedNightVisionDirty(inst)
    end
end

AddPrefabPostInit("kukude", function(inst)

    inst._forced_nightvision = net_bool(inst.GUID, "kkd_forced_nightvision","onforcednightvisiondirty")
    --inst._forced_nightvision:set(false)
    inst:ListenForEvent("playeractivated", OnPlayerActivated)
    inst:ListenForEvent("playerdeactivated", OnPlayerDeactivated)
end)